home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / demos / 134 / gfa / xmodem.lst < prev   
Encoding:
File List  |  1987-04-17  |  3.3 KB  |  180 lines

  1. Rem -->  Following definitions are for XMODEM  <--
  2. Soh=1      ! Start Of Header
  3. Eot=4      ! End Of Transmission
  4. Ack=6      ! ACKnowledge
  5. Nak=21     ! Negative AcKnowledge
  6. Can=24     ! CANcel
  7. Return
  8. '
  9. Procedure Xmodem_receive(Filename$)
  10. Oldx%=Crscol
  11. Oldy%=Crslin
  12. Void Xbios(21,0)
  13. Sget Screen1$
  14. Cls
  15. '
  16. Xmodem_part1:
  17. Open "O",#1,Filename$
  18. Print At(35,1);Rv1$;"XMODEM receive";Rv0$
  19. Print
  20. Print At(10,3);"Receiving:  ";Green$;Upper$(Filename$);Char$
  21. Print
  22. Block%=1
  23. Try%=1
  24. '
  25. Xmodem_part2:
  26. @Clear_modem
  27. Void Bios(3,1,Nak)
  28. Time_out=0
  29. '
  30. Xmodem_part3:
  31. Print At(10,7);Rv1$;"Block-->";Rv0$;Block%;"    ";Rv1$;"Try-->";Rv0$;Try%
  32. '
  33. Xmodem_part4:
  34. Print At(10,9);"Time out:";Time_out
  35. '
  36. Xmodem_part5:
  37. Stat!=Bios(1,1)
  38. If Stat!=0 Then
  39.   Goto Xmodem_part6
  40. Else
  41.   Goto Xmodem_part7
  42. Endif
  43. '
  44. Xmodem_part6:
  45. Inc Time_out
  46. If (Time_out/128)=(128*10) Then
  47.   Goto Xmodem_part11
  48. Endif
  49. If (Time_out/128)=Int(Time_out/128) Then
  50.   Goto Xmodem_part2
  51. Else
  52.   Goto Xmodem_part5
  53. Endif
  54. '
  55. Xmodem_part7:
  56. Da%=Bios(2,1)
  57. If Da%=Soh Then
  58.   Goto Xmodem_part8
  59. Endif
  60. If Da%=Eot Then
  61.   Goto Xmodem_part12
  62. Endif
  63. If Da%=Can Then
  64.   Goto Xmodem_part11
  65. Endif
  66. Goto Xmodem_part6
  67. '
  68. Xmodem_part8:
  69. Block_numb%=0
  70. Block_comp%=0
  71. Block_numb%=Bios(2,1)
  72. Block_comp%=Bios(2,1)
  73. Print At(10,11);"Block number: ";Block_numb%;"    ";"Block Compliment: ";Block_comp%
  74. Print At(24,13);Space$(20)
  75. Check%=0
  76. Block$=""
  77. Checksum%=0
  78. Print At(10,13);"Byte received:";
  79. For Byte=1 To 128
  80.   Print At(24,13);Byte
  81.   Da%=0
  82.   Byte_data:
  83.   Abort$=Inkey$
  84.   Exit If Abort$=Chr$(24)
  85.   If Bios(1,1) Then
  86.     Da%=Bios(2,1)
  87.     Check%=Check%+Da%
  88.     Block$=Block$+Chr$(Da%)
  89.   Else
  90.     Goto Byte_data
  91.   Endif
  92. Next Byte
  93. Print At(24,13);"Got 128 bytes!"
  94. If Abort$=Chr$(24) Then
  95.   Goto Xmodem_part11
  96. Else
  97.   Checksum%=Check% And 255
  98. Endif
  99. Check:
  100. Abort$=Inkey$
  101. If Abort$=Chr$(24) Then
  102.   Goto Xmodem_part11
  103. Endif
  104. Check_sum%=0
  105. Print At(10,15);Space$(50)
  106. Print At(10,15);"Awaiting checksum.........."
  107. If Bios(1,1)=-1 Then
  108.   Check_sum%=Inp(1)
  109. Else
  110.   Goto Check
  111. Endif
  112. Print At(10,15);Space$(50)
  113. Print At(10,15);"Our check: ";Checksum%;"   Their check:";Check_sum%
  114. If Checksum%=Check_sum% Then
  115.   Goto Xmodem_part9
  116. Else
  117.   Goto Xmodem_part10
  118. Endif
  119. '
  120. Xmodem_part9:
  121. Print #1,Block$;
  122. Try%=1
  123. Inc Block%
  124. Time_out=0
  125. B_out=0
  126. @Clear_modem
  127. Out 1,Ack
  128. Goto Xmodem_part3
  129. '
  130. Xmodem_part10:
  131. Inc Try%
  132. If Try%>10 Then
  133.   Goto Xmodem_part11
  134. Else
  135.   @Clear_modem
  136. Endif
  137. Goto Xmodem_part2
  138. '
  139. Xmodem_part11:
  140. Out 1,Can
  141. Out 1,Can
  142. Out 1,Can
  143. Close #1
  144. Kill Filename$
  145. Print At(10,17);"Status: ";Red$;"XMODEM CANCELLED -- ";Char$;
  146. Print Green$;Upper$(Filename$);Char$;" deleted."
  147. Print At(28,20);"PRESS ANY KEY"
  148. Void Inp(2)
  149. Goto Xmodem_end
  150. '
  151. Xmodem_part12:
  152. Out 1,Ack
  153. Close #1
  154. Print At(10,17);"Status: ";Green$;"XMODEM COMPLETE.  ";Red$;
  155. Print Upper$(Filename$);
  156. Print Char$;" received."
  157. Print At(28,20);"PRESS ANY KEY"
  158. Void Inp(2)
  159. Goto Xmodem_end
  160. '
  161. Xmodem_end:
  162. Cls
  163. @Clear_modem
  164. Sput Screen1$
  165. Clr Screen1$
  166. Print At(Oldx%,Oldy%);
  167. Void Xbios(21,1)
  168. Return
  169. '
  170. Procedure Clear_modem
  171. Rem -->  Clears the modem of any extraneous data  <--
  172. Do
  173.   Test!=Bios(1,1)
  174.   Exit If Test!=0
  175.   Void Inp(1)
  176. Loop
  177. @Clear_iorec_buffer(1024)
  178. Return
  179. '
  180. əəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəə